goog.provide('dkpoints.status.Message');

goog.require('dkpoints.status.templates');

goog.require('soy');



/**
 * Encapsulation of a single message.
 * @param {string} message The message text to display.
 * @param {string} messageID The ID of the message.
 * @param {Element} parentEl The parent element into which this message
 *    should be inserted.
 * @constructor
 */
dkpoints.status.Message = function(message, messageID, parentEl) {
  /**
   * @type {string}
   * @private
   */
  this.message_ = message;

  /**
   * @type {string}
   * @private
   */
  this.messageID_ = messageID;

  var messageEl = null;
  /**
   * @type {Element}
   * @private
   */
  this.element_ = messageEl =
      soy.renderAsElement(dkpoints.status.templates.statusMessage,
                          {message: message});

  /**
   * @type {Element}
   * @private
   */
  this.parentEl_ = parentEl;
  parentEl.appendChild(messageEl);
};


/**
 * Update the message.
 * @param {string} message The new message text.
 * @return {boolean}  True if the message was updated, false otherwise.
 */
dkpoints.status.Message.prototype.updateMessage = function(message) {
  this.element_.innerHTML =
      dkpoints.status.templates.statusMessage({message: message});

  return true;
};


/**
 * Remove the message.
 * @return {boolean} True if the message was deleted, false otherwise.
 */
dkpoints.status.Message.prototype.dispose = function() {
  this.parentEl_.removeChild(this.element_);
  this.element_.innerHTML = '';
  this.parentEl_ = this.element_ = null;

  return true;
};
